<?php
namespace app\model\SysDepartment;
use app\model\BaseModel;
use app\utils\CamlHump;
use think\facade\Db;
use think\Model;
class SysDepartmentRole extends BaseModel
{
    protected $convertNameToCamel = true;
    protected $name = 'sys_department_role';

    static function  build($data)
    {
        $emptyData = [];

        $emptyData['id']= $data['id' ] ?? 0;




        $emptyData['departId']= $data['departId' ] ?? 0;




        $emptyData['roleId']= $data['roleId' ] ?? 0;




        $emptyData['tenantType']= $data['tenantType' ] ?? 0;




        $emptyData['tenantId']= $data['tenantId' ] ?? 0;




        $emptyData['delState']= $data['delState' ] ?? 0;





        //是 VARCHAR 类型的 VARCHAR
        $emptyData['addUser']= $data['addUser' ] ?? '';



        $emptyData['addUserId']= $data['addUserId' ] ?? 0;






        //是 VARCHAR 类型的 DATETIME
        $emptyData['addTime']= $data['addTime' ] ?? date("Y-m-d H:i:s", time());



        //是 VARCHAR 类型的 VARCHAR
        $emptyData['editUser']= $data['editUser' ] ?? '';



        $emptyData['editUserId']= $data['editUserId' ] ?? 0;






        //是 VARCHAR 类型的 DATETIME
        $emptyData['lastEditTime']= $data['lastEditTime' ] ?? date("Y-m-d H:i:s", time());


        $emptyData['serverNumber']= $data['serverNumber' ] ?? 0;



        return $emptyData;
    }
    static function createQuery($queryData)
    {
        $query = Db::table('sys_department_role');

        //是int类型的 BIGINT
        if(isset($queryData['id'])&&$queryData['id']>0){
            $query->where('id', $queryData['id']);
        }



        //是int类型的 BIGINT
        if(isset($queryData['departId'])&&$queryData['departId']>0){
            $query->where('depart_id', $queryData['departId']);
        }



        //是int类型的 BIGINT
        if(isset($queryData['roleId'])&&$queryData['roleId']>0){
            $query->where('role_id', $queryData['roleId']);
        }



        //是int类型的 TINYINT
        if(isset($queryData['tenantType'])&&$queryData['tenantType']>0){
            $query->where('tenant_type', $queryData['tenantType']);
        }



        //是int类型的 BIGINT
        if(isset($queryData['tenantId'])&&$queryData['tenantId']>0){
            $query->where('tenant_id', $queryData['tenantId']);
        }



        //是int类型的 TINYINT
        if(isset($queryData['delState'])&&$queryData['delState']>0){
            $query->where('del_state', $queryData['delState']);
        }



        //是 VARCHAR 类型的 VARCHAR
        if(isset($queryData['addUser'])&&$queryData['addUser']!=''){
            $query->where('add_user', $queryData['addUser']);
        }


        //是int类型的 BIGINT
        if(isset($queryData['addUserId'])&&$queryData['addUserId']>0){
            $query->where('add_user_id', $queryData['addUserId']);
        }




        //是 VARCHAR 类型的 DATETIME
        if(isset($queryData['addTime'])&&$queryData['addTime']!=''){
            $query->where('add_time', $queryData['addTime']);
        }


        //是 VARCHAR 类型的 VARCHAR
        if(isset($queryData['editUser'])&&$queryData['editUser']!=''){
            $query->where('edit_user', $queryData['editUser']);
        }


        //是int类型的 BIGINT
        if(isset($queryData['editUserId'])&&$queryData['editUserId']>0){
            $query->where('edit_user_id', $queryData['editUserId']);
        }




        //是 VARCHAR 类型的 DATETIME
        if(isset($queryData['lastEditTime'])&&$queryData['lastEditTime']!=''){
            $query->where('last_edit_time', $queryData['lastEditTime']);
        }

        //是int类型的 SMALLINT
        if(isset($queryData['serverNumber'])&&$queryData['serverNumber']>0){
            $query->where('server_number', $queryData['serverNumber']);
        }



        $query->where('del_state', 1);

        return   $query;

    }
    static function addPlus($data){
        $addWidthDefault = static::build($data);
        $result = static::create($addWidthDefault);
        return $result;
    }
    static function updatePlus($data, $id)
    {
        $result = static::update($data, ['id' => $id]);
        return $result;
    }
    static function deletePlus($id)
    {
        $result = static::destroy($id);
        return $result;
    }

    static function findOne($id){
        $query=Db::table('sys_department_role')->where("id", $id);
        $one = CamlHump::toCamlObj($query->find());
        return $one;
    }
    static function exitOne($query){
        return $query->count()>0;
    }

}